<?php

namespace App\Admin\Controllers\Divination;

use App\Admin\Repositories\Divination;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Show;
use Dcat\Admin\Widgets\Card;
use Dcat\Admin\Widgets\Table;
use function Termwind\render;

class DivinationController extends AdminController
{
    protected int $id;
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Divination(['answers']), function (Grid $grid) {

            $grid->model()->orderBy('id','desc');
            $grid->column('id')->sortable();
            $grid->column('uid');
            $grid->column('type')->using([1=>'八字六爻',2=>'行星星座',3=>'塔罗牌']);
            $grid->column('content');
            $grid->column('answer_num');
            $grid->column('price');
            $grid->column('status')->using([0=>'待支付',1=>'已支付',2=>'取消','3'=>'已回答',4=>'已完成'])->filter();
            $grid->column('pay_time','支付时间')->sortable();
            $grid->column('created_at');
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
            });
            $grid->disableCreateButton();
            $grid->disableEditButton();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Divination(), function (Show $show) {
            $show->field('id');
            $show->field('uid');
            $show->field('type');
            $show->field('content');
            $show->field('answer_num');
            $show->field('price');
            $show->field('divination');
            $show->field('status')->using([0=>'待支付',1=>'已支付',2=>'取消','3'=>'已回答',4=>'已完成']);
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Divination(), function (Form $form) {
            $form->display('id');
            $form->text('uid');
            $form->text('type');
            $form->text('content');
            $form->text('answer_num');
            $form->text('price');
            $form->text('divination');
            $form->text('status');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
